package com.zhangyj.db;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Array;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.sql.Date;
import java.sql.NClob;
import java.sql.ParameterMetaData;
import java.sql.PreparedStatement;
import java.sql.Ref;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.RowId;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.SQLXML;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Map;

public class NamePrepareStatement {
	private PreparedStatement ps;
	private Map<String, Integer> map;

	NamePrepareStatement(PreparedStatement ps, Map<String, Integer> map) {
		this.ps = ps;
		this.map = map;
	}

	private int getIndex(String parameterName) {
		Integer index = this.map.get(parameterName.toLowerCase());
		if (index == null) {
			return -1;
		}
		return this.map.get(parameterName.toLowerCase());
	}

	public void addBatch() throws SQLException {
		ps.addBatch();

	}

	public void clearParameters() throws SQLException {
		ps.clearParameters();

	}

	public boolean execute() throws SQLException {
		return ps.execute();
	}

	public ResultSet executeQuery() throws SQLException {
		return ps.executeQuery();
	}

	public int executeUpdate() throws SQLException {
		return ps.executeUpdate();
	}

	public ResultSetMetaData getMetaData() throws SQLException {
		return ps.getMetaData();
	}

	public ParameterMetaData getParameterMetaData() throws SQLException {
		return ps.getParameterMetaData();
	}

	public void setArray(String parameterName, Array x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setArray(index, x);

	}

	public void setAsciiStream(String parameterName, InputStream x, int length) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setAsciiStream(index, x, length);
	}

	public void setAsciiStream(String parameterName, InputStream x, long length) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setAsciiStream(index, x, length);
	}

	public void setAsciiStream(String parameterName, InputStream x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setAsciiStream(index, x);
	}

	public void setBigDecimal(String parameterName, BigDecimal x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setBigDecimal(index, x);
	}

	public void setBinaryStream(String parameterName, InputStream x, int length) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setBinaryStream(index, x, length);
	}

	public void setBinaryStream(String parameterName, InputStream x, long length) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setBinaryStream(index, x, length);
	}

	public void setBinaryStream(String parameterName, InputStream x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setBinaryStream(index, x);
	}

	public void setBlob(String parameterName, Blob x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setBlob(index, x);
	}

	public void setBlob(String parameterName, InputStream inputStream, long length) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setBlob(index, inputStream, length);
	}

	public void setBlob(String parameterName, InputStream inputStream) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setBlob(index, inputStream);
	}

	public void setBoolean(String parameterName, boolean x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setBoolean(index, x);
	}

	public void setByte(String parameterName, byte x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setByte(index, x);
	}

	public void setBytes(String parameterName, byte[] x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setBytes(index, x);
	}

	public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setCharacterStream(index, reader, length);
	}

	public void setCharacterStream(String parameterName, Reader reader, long length) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setCharacterStream(index, reader, length);
	}

	public void setCharacterStream(String parameterName, Reader reader) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setCharacterStream(index, reader);
	}

	public void setClob(String parameterName, Clob x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setClob(index, x);
	}

	public void setClob(String parameterName, Reader reader, long length) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setClob(index, reader, length);
	}

	public void setClob(String parameterName, Reader reader) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setClob(index, reader);
	}

	public void setDate(String parameterName, Date x, Calendar cal) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setDate(index, x, cal);
	}

	public void setDate(String parameterName, Date x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setDate(index, x);
	}

	public void setDouble(String parameterName, double x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setDouble(index, x);
	}

	public void setFloat(String parameterName, float x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setFloat(index, x);
	}

	public void setInt(String parameterName, int x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setInt(index, x);
	}

	public void setLong(String parameterName, long x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setLong(index, x);
	}

	public void setNCharacterStream(String parameterName, Reader value, long length) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setNCharacterStream(index, value, length);
	}

	public void setNCharacterStream(String parameterName, Reader value) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setNCharacterStream(index, value);
	}

	public void setNClob(String parameterName, NClob value) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setNClob(index, value);
	}

	public void setNClob(String parameterName, Reader reader, long length) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setNClob(index, reader, length);
	}

	public void setNClob(String parameterName, Reader reader) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setNClob(index, reader);
	}

	public void setNString(String parameterName, String value) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setNString(index, value);
	}

	public void setNull(String parameterName, int sqlType, String typeName) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setNull(index, sqlType, typeName);
	}

	public void setNull(String parameterName, int sqlType) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setNull(index, sqlType);
	}

	public void setObject(String parameterName, Object x, int targetSqlType, int scaleOrLength) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setObject(index, x, targetSqlType, scaleOrLength);
	}

	public void setObject(String parameterName, Object x, int targetSqlType) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setObject(index, x, targetSqlType);
	}

	public void setObject(String parameterName, Object x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setObject(index, x);
	}

	public void setRef(String parameterName, Ref x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setRef(index, x);
	}

	public void setRowId(String parameterName, RowId x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setRowId(index, x);
	}

	public void setShort(String parameterName, short x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setShort(index, x);
	}

	public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setSQLXML(index, xmlObject);
	}

	public void setString(String parameterName, String x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setString(index, x);
	}

	public void setTime(String parameterName, Time x, Calendar cal) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setTime(index, x, cal);
	}

	public void setTime(String parameterName, Time x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setTime(index, x);
	}

	public void setTimestamp(String parameterName, Timestamp x, Calendar cal) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setTimestamp(index, x, cal);
	}

	public void setTimestamp(String parameterName, Timestamp x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setTimestamp(index, x);
	}

	/**
	 * @deprecated
	 */
	public void setUnicodeStream(String parameterName, InputStream x, int length) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setUnicodeStream(index, x, length);
	}

	public void setURL(String parameterName, URL x) throws SQLException {
		int index = getIndex(parameterName);
		if (index == -1)
			return;
		ps.setURL(index, x);
	}

	public void addBatch(String sql) throws SQLException {
		ps.addBatch(sql);
	}

	public void cancel() throws SQLException {
		ps.cancel();
	}

	public void clearBatch() throws SQLException {
		ps.clearBatch();
	}

	public void clearWarnings() throws SQLException {
		ps.clearWarnings();
	}

	public void close() throws SQLException {
		ps.close();
	}

	public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
		return ps.execute(sql, autoGeneratedKeys);
	}

	public boolean execute(String sql, int[] columnIndexes) throws SQLException {
		return ps.execute(sql, columnIndexes);
	}

	public boolean execute(String sql, String[] columnNames) throws SQLException {
		return ps.execute(sql, columnNames);
	}

	public boolean execute(String sql) throws SQLException {
		return ps.execute(sql);
	}

	public int[] executeBatch() throws SQLException {
		return ps.executeBatch();
	}

	public ResultSet executeQuery(String sql) throws SQLException {
		return ps.executeQuery(sql);
	}

	public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
		return ps.executeUpdate(sql, autoGeneratedKeys);
	}

	public int executeUpdate(String sql, int[] columnIndexes) throws SQLException {
		return ps.executeUpdate(sql, columnIndexes);
	}

	public int executeUpdate(String sql, String[] columnNames) throws SQLException {
		return ps.executeUpdate(sql, columnNames);
	}

	public int executeUpdate(String sql) throws SQLException {
		return ps.executeUpdate(sql);
	}

	public Connection getConnection() throws SQLException {
		return ps.getConnection();
	}

	public int getFetchDirection() throws SQLException {
		return ps.getFetchDirection();
	}

	public int getFetchSize() throws SQLException {
		return ps.getFetchSize();
	}

	public ResultSet getGeneratedKeys() throws SQLException {
		return ps.getGeneratedKeys();
	}

	public int getMaxFieldSize() throws SQLException {
		return ps.getMaxFieldSize();
	}

	public int getMaxRows() throws SQLException {
		return ps.getMaxRows();
	}

	public boolean getMoreResults() throws SQLException {
		return ps.getMoreResults();
	}

	public boolean getMoreResults(int current) throws SQLException {
		return ps.getMoreResults(current);
	}

	public int getQueryTimeout() throws SQLException {
		return ps.getQueryTimeout();
	}

	public ResultSet getResultSet() throws SQLException {
		return ps.getResultSet();
	}

	public int getResultSetConcurrency() throws SQLException {
		return ps.getResultSetConcurrency();
	}

	public int getResultSetHoldability() throws SQLException {
		return ps.getResultSetHoldability();
	}

	public int getResultSetType() throws SQLException {
		return ps.getResultSetType();
	}

	public int getUpdateCount() throws SQLException {
		return ps.getUpdateCount();
	}

	public SQLWarning getWarnings() throws SQLException {
		return ps.getWarnings();
	}

	public boolean isClosed() throws SQLException {
		return ps.isClosed();
	}

	public boolean isPoolable() throws SQLException {
		return ps.isPoolable();
	}

	public void setCursorName(String name) throws SQLException {
		ps.setCursorName(name);
	}

	public void setEscapeProcessing(boolean enable) throws SQLException {
		ps.setEscapeProcessing(enable);
	}

	public void setFetchDirection(int direction) throws SQLException {
		ps.setFetchDirection(direction);
	}

	public void setFetchSize(int rows) throws SQLException {
		ps.setFetchSize(rows);
	}

	public void setMaxFieldSize(int max) throws SQLException {
		ps.setMaxFieldSize(max);
	}

	public void setMaxRows(int max) throws SQLException {
		ps.setMaxRows(max);
	}

	public void setPoolable(boolean poolable) throws SQLException {
		ps.setPoolable(poolable);
	}

	public void setQueryTimeout(int seconds) throws SQLException {
		ps.setQueryTimeout(seconds);
	}

	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		return ps.isWrapperFor(iface);
	}

	public <T> T unwrap(Class<T> iface) throws SQLException {
		return ps.unwrap(iface);
	}

}
